package dao

import (
	"beetle/app"
	"beetle/models"
	"fmt"
	"strconv"
	"strings"
)

type User struct{}

func (this User) GetUserById(id int) (models.User, error) {
	var userModel models.User
	err := app.DB.QueryRow("select id,name from user where id = ?", id).Scan(&userModel.Id, &userModel.Name)
	if err != nil {
		fmt.Printf("scan failed, err:%v\n", err)
	}
	return userModel, err
}

func (user User) GetIds(users []models.User) string {
	ids := []string{}
	var is_exist bool
	for _, user := range users {
		is_exist = false
		for _, id := range ids {
			if id == strconv.Itoa(user.Id) {
				is_exist = true
			}
		}
		if is_exist == false {
			ids = append(ids, strconv.Itoa(user.Id))
		}
	}
	return strings.Join(ids, ",")
}
